#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct jie
{
	char n;
	int i;
	jie * next;
}dian;
dian * init();
dian * wei(dian * p);
void jin(dian * p,char n);
dian * pre(dian * p,dian * a);
void chu(dian * p);
char topn(dian * p);
int topi(dian * p);
dian * toi(dian * p,int i);
void puti(dian * p,int i);
void putall(dian * p);


dian * init()
{
	dian * a=NULL;
	a=(dian *)malloc(sizeof(dian));
	a->n ='!';
	a->i =0;
	a->next =NULL;
	return a;
}
dian * wei(dian * p)
{
	dian * a=p;
	while(a!=NULL&&a->next !=NULL)
	{
		a=a->next ;
	}
	return a;
}
void jin(dian * p,char n)
{
	int i=0;
	i=topi(p);
	dian * a=NULL;
	a=init();
	a->n =n;
	a->i =i+1;
	dian * b=NULL;
	b=wei(p);
	b->next =a;
}
dian * pre(dian * p,dian * a)
{
	dian * b=p;
	while(b!=NULL&&b->next !=a)
	{
		b=b->next ;
	}
	return b;
}
void chu(dian * p)
{
	dian * a=NULL;
	a=wei(p);
	dian * b=NULL;
	b=pre(p,a);
	b->next =NULL;
	free(a);
}
char topn(dian * p)
{
	dian * a=NULL;
	a=wei(p);
	return a->n ;
}
int topi(dian * p)
{
	dian * a=NULL;
	a=wei(p);
	return a->i ;
}
dian * toi(dian * p,int i)
{
	dian * a=p->next ;
	while(a!=NULL&&a->i !=i)
	{
		a=a->next ;
	}
	return a;
}
void puti(dian * p,int i)
{
	dian * a=NULL;
	a=toi(p,i);
	printf("%c\n",a->n );
}
void putall(dian * p)
{
	dian * a=p;
	int i=0,w=0;
	w=topi(p);
	for(i=1;i<=w;i++)
	{
		puti(p,i);
	}
}
int prior(char x)
{
	if(x=='*'||x=='/')return 4;
	else if(x=='+'||x=='-')return 3;
	else if(x=='(')return 2;
	else if(x=='#')return 1;
	else
		return 0;
}
void main()
{
	char shi[20]="3*(5-2)+7";
	char hou[20];
	char x;
	dian * head=NULL;
	head=init();
	jin(head,'#');
	int n;
	n=strlen(shi);
	shi[n]='#';
	shi[n+1]='\0';
	int i=0,k=0;
	while(shi[i]!='\0')
	{
		if(shi[i]>='0'&&shi[i]<='9')
		{
			hou[k]=shi[i];
			k++;
		}
		else
		{
			switch(shi[i])
			{
			case'(':
				{
					jin(head,shi[i]);
					break;
				}
			case')':
				{
					x=topn(head);
					chu(head);
					while(x!='(')
					{
						hou[k]=x;
						k++;
						x=topn(head);
						chu(head);
					}
					break;
				}
			default:
				{
					x=topn(head);
					while(prior(x)>=prior(shi[i]))
					{
						hou[k]=x;
						k++;
						chu(head);
						x=topn(head);
					}
					if(shi[i]!='#')
						jin(head,shi[i]);
				}//default
			}//switch
		}//else
		i++;
	}//while
	hou[k]='\0';
}//main